#!/usr/bin/env python
# -*- coding: UTF-8 -*-

'''Benchmark the Elementary Cellular Automata implementation'''

import sys
import cProfile
from timeit import Timer

from elementary import ElementaryCellularAutomata

ROWS = 100


def provide_profile_data():
    for rule in range(257):
        ca = ElementaryCellularAutomata(rule)

        for _ in range(ROWS):
            ca.game_loop()


def time_it():
    t = Timer("provide_profile_data()", "from __main__ import provide_profile_data")
    print t.timeit(number=10)


def generate_profile():
    command = "provide_profile_data()"
    cProfile.runctx(command, globals(), locals(), filename='elementary.profile')

if __name__ == '__main__':
    arg = sys.argv[1].lower()

    if arg == 'time':
        time_it()
    elif arg == 'profile':
        generate_profile()

